package sky.tro;

import org.hibernate.Hibernate;
import org.hibernate.type.Type;
import org.joda.time.DateTime;


import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * User: Gauss
 * Date: 30.04.13
 * Time: 14:31
 * To change this template use File | Settings | File Templates.
 */
public class TicketFinder {
    private String departureCity;
    private String destinationCity;
    private Date departureDateFrom;
    private Date departureDateTo;
    private Date destinationDateFrom;
    private Date destinationDateTo;
    private String ticketType;
    private Integer ticketCount;
    private Integer priceFrom;
    private Integer priceTo;

    public String getDepartureCity() {
        return departureCity;
    }

    public void setDepartureCity(String departureCity) {
        this.departureCity = departureCity;
    }

    public String getDestinationCity() {
        return destinationCity;
    }

    public void setDestinationCity(String destinationCity) {
        this.destinationCity = destinationCity;
    }

    public Date getDepartureDateFrom() {
        return departureDateFrom;
    }

    public void setDepartureDateFrom(Date departureDateFrom) {
        this.departureDateFrom = departureDateFrom;
    }

    public Date getDepartureDateTo() {
        return departureDateTo;
    }

    public void setDepartureDateTo(Date departureDateTo) {
        this.departureDateTo = departureDateTo;
    }

    public Date getDestinationDateFrom() {
        return destinationDateFrom;
    }

    public void setDestinationDateFrom(Date destinationDateFrom) {
        this.destinationDateFrom = destinationDateFrom;
    }

    public Date getDestinationDateTo() {
        return destinationDateTo;
    }

    public void setDestinationDateTo(Date destinationDateTo) {
        this.destinationDateTo = destinationDateTo;
    }

    public String getTicketType() {
        return ticketType;
    }

    public void setTicketType(String ticketType) {
        this.ticketType = ticketType;
    }

    public Integer getTicketCount() {
        return ticketCount;
    }

    public void setTicketCount(Integer ticketCount) {
        this.ticketCount = ticketCount;
    }

    public Integer getPriceFrom() {
        return priceFrom;
    }

    public void setPriceFrom(Integer priceFrom) {
        this.priceFrom = priceFrom;
    }

    public Integer getPriceTo() {
        return priceTo;
    }

    public void setPriceTo(Integer priceTo) {
        this.priceTo = priceTo;
    }

    public List<ParameterAndCriteria> getCriteriaList() {
        List<ParameterAndCriteria> list = new ArrayList<ParameterAndCriteria>();
        if (!departureCity.isEmpty()) {
            //0 - equals
            //1 - less or equals
            //2 - more or equals
            list.add(new ParameterAndCriteria("departureAirport.city.name",
                    0, departureCity, Hibernate.STRING));
        }
        if (!destinationCity.isEmpty()) {
            list.add(new ParameterAndCriteria("destinationAirport.city.name",
                    0, destinationCity, Hibernate.STRING));
        }
        if (departureDateFrom != null) {
            list.add(new ParameterAndCriteria("departureDate",
                    2, departureDateFrom, Hibernate.TIMESTAMP));
        }
        if (departureDateTo != null) {
            list.add(new ParameterAndCriteria("departureDate",
                    1, departureDateTo, Hibernate.TIMESTAMP));
        }
        if (destinationDateFrom != null) {
            list.add(new ParameterAndCriteria("destinationDate",
                    2, destinationDateFrom, Hibernate.TIMESTAMP));
        }
        if (destinationDateTo != null) {
            list.add(new ParameterAndCriteria("destinationDate",
                    1, destinationDateTo, Hibernate.TIMESTAMP));
        }
        list.add(new ParameterAndCriteria("free"+ticketType+"Places",
                2, ticketCount, Hibernate.INTEGER));
        if (priceFrom != null) {
            list.add(new ParameterAndCriteria(ticketType.replaceFirst("[A-Z]{1}", ticketType.substring(0,1).toLowerCase())+"Cost",
                    2, priceFrom, Hibernate.INTEGER));
        }
        if (priceTo != null) {
            list.add(new ParameterAndCriteria(ticketType.replaceFirst("[A-Z]{1}", ticketType.substring(0,1).toLowerCase())+"Cost",
                    1, priceTo, Hibernate.INTEGER));
        }
        return list;
    }
}
